﻿#include "mythread.h"
#include<QDebug>

MyThread::MyThread(QObject *parent) : QThread(parent)
{
    m_pTimer = new QTimer(this);
    connect(m_pTimer, &QTimer::timeout, this, &MyThread::setValue);

    connect(this, &MyThread::sigStart, this, &MyThread::startTimer);
}

MyThread::~MyThread()
{
}

void MyThread::run()
{
    qWarning() << "child Thread id:" << QThread::currentThread();
//    qWarning() << "run";
//    sleep(10);

    emit sigStart();

    this->exec();
}

void MyThread::startTimer()
{
    m_iValue = 0;
    if(!m_pTimer->isActive())
    {
        m_pTimer->start(100);
    }
}

void MyThread::setValue()
{
    m_iValue++;
    emit sigImportRefresh(m_iValue);
    if(m_iValue == 99)
    {
        m_pTimer->stop();
        this->quit();
        this->wait();
    }
}
